# set CPUS for Linux or FreeBSD
PLATFORM := $(shell uname)
CPUS := $(strip $(if $(shell echo $(PLATFORM)|grep Linux),\
	$(shell cat /proc/cpuinfo|grep -c processor),\
	$(shell sysctl -a | egrep -i 'hw.ncpu' | cut -d: -f2)))

CENTOS_VERSION=centos$(shell echo `cat /etc/issue | grep CentOS| cut -d' ' -f3`)


ifeq ($(PLATFORM), Linux)
#RPATH=-Wl,-rpath=/usr/local/lib -Wl,-rpath=../libs
RPATH=
else
RPATH=-Wl,-R
endif


BIN=example_engine.so

INCLUDE=-I/usr/local/include \
	    -I/usr/include \
	    -I../include

CPPFLAGS=-g -O3 -Wall -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings -Wsign-compare -Winvalid-pch -fms-extensions $(INCLUDE) 

LDFLAGS=-L/usr/local/lib -L/usr/lib64 -L//usr/lib $(RPATH)
LIBS:=-lpthread \
	  -levent \
	  -ldl \
	  -lgflags \
	  -lglog
	

CC=g++

SOURCE:=$(wildcard *.cpp)

OBJS:=$(patsubst %.cpp, %.o, $(SOURCE))
DEPS:=$(patsubst %.o, %.d, $(OBJS))

CPPFLAGS += -MMD

all: $(BIN)


deps: $(DEPS)

objs: $(OJBS)

-include $(DEPS)

example_engine.so: example_engine.cpp ../utility/ugx_palloc.cpp
	$(CC) $(CPPFLAGS) -fpic -shared $^ -o $@ $(LDFLAGS) $(LIBS)
	mv $@ ../../libs/

clean:
	@$(RM) $(OBJS) $(DEPS) $(BIN) *.d

.PHONY: all deps objs debug release version clean

